package com.ruoyi.project.hissys.service.impl;

import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.project.hissys.domain.HisSysDept;
import com.ruoyi.project.hissys.mapper.HisSysDeptMapper;
import com.ruoyi.project.hissys.service.IHisSysDeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

@Service
public class HisSysDeptServiceImpl implements IHisSysDeptService {

    @Autowired
    HisSysDeptMapper hisSysDeptMapper;

    @Override
    public List<HisSysDept> selectDeptList(HisSysDept dept) {
        List<HisSysDept> hisSysDepts = hisSysDeptMapper.selectDeptList(dept);
        return hisSysDepts;
    }

    @Override
    public int insertDept(HisSysDept dept) {
        return hisSysDeptMapper.insertSingleDept(dept);
    }

    @Override
    public HisSysDept selectDeptById(Long deptId) {
        return hisSysDeptMapper.selectDeptById(deptId);
    }

    @Override
    public int updateDept(HisSysDept dept) {
        return hisSysDeptMapper.updateByDept(dept);
    }

    @Override
    public String checkDeptNameUnique(HisSysDept dept) {
        HisSysDept info = hisSysDeptMapper.selectDeptByName(dept.getDeptName());
        if(Objects.nonNull(info)){
            // 有数据
            return UserConstants.NOT_UNIQUE;
        }
        return UserConstants.UNIQUE;
    }
}
